package com.blog4j.article.component;

import com.blog4j.api.client.FeignServer;
import com.blog4j.api.client.FeignUser;
import com.blog4j.api.vo.NoticeEmailVo;
import com.blog4j.api.vo.UserIllegalRecordVo;
import com.blog4j.api.vo.UserInfoVo;
import com.blog4j.common.model.LogVo;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author 98k灬
 * @version v1.0.0
 * @Description : 功能描述
 * @Create on : 2024/9/10 12:23
 **/
@Component
@Slf4j
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class ApiCallService {
    private final FeignUser feignUser;
    private final FeignServer feignServer;

    /**
     * 记录用户不合法行为
     *
     * @param recordVo 不合法行为信息
     */
    public void addUserIllegalRecord(UserIllegalRecordVo recordVo) {
        feignUser.addUserIllegalRecord(recordVo);
    }

    /**
     * 记录日志信息
     *
     * @param logVo 日志信息
     */
    public void addLog(LogVo logVo) {
        feignServer.addLog(logVo);
    }

    /**
     * 发送邮件给文章审批人
     *
     * @param email 接收方邮件地址
     * @param articleTitle 文章标题
     */
    public void sendSystemEmailToArticleCreater(String email, String articleTitle) {
        feignServer.sendSystemEmailToArticleCreater(email, articleTitle);
    }

    /**
     * 根据用户ID获取用户信息
     *
     * @param userId 用户ID
     * @return 用户信息
     */
    public UserInfoVo getUserInfoByUserId(String userId) {
        return feignUser.getUserInfoByUserId(userId);
    }

    /**
     * 根据映射ID获取用户信息
     *
     * @param id 映射ID
     * @return 用户信息
     */
    public UserInfoVo getUserInfoById(Integer id) {
        return feignUser.getUserInfoById(id);
    }

    /**
     * 发送邮件给文章审批人
     *
     * @param email 接收方邮件地址
     * @param userName 接收方用户名称
     */
    public void sendSystemEmailToArticleApproveUser(String email, String userName) {
        NoticeEmailVo emailVo = NoticeEmailVo.builder()
                .acceptUserName(userName)
                .toEmail(email)
                .build();
        feignServer.sendSystemEmailToArticleApproveUser(emailVo);
    }
}
